package com.jackstraw.jack_base.mq.common.config;

import com.jackstraw.jack_base.mq.common.entity.MQConsumer;
import com.jackstraw.jack_base.mq.common.entity.MQEntity;
import com.jackstraw.jack_base.mq.common.entity.MQProducer;
import com.jackstraw.jack_base.mq.common.entity.MQProperties;
import com.jackstraw.jack_base.mq.common.entity.MQRoutingTemplate;
import com.jackstraw.jack_base.mq.common.entity.MQTemplateS;
import com.jackstraw.jack_base.util.CollectionUtil;
import com.jackstraw.jack_base.util.ObjectUtil;
import com.jackstraw.jack_base.util.StringUtil;
import com.jackstraw.jack_base.util.EnvironmentUtil;
import com.jackstraw.jack_base.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;

@Slf4j
public abstract class AbstractMQConfiguration<MP extends MQProperties<E, P, C, MTS>,
        E extends MQEntity<P, C, MTS, E>,
        P extends MQProducer,
        C extends MQConsumer,
        MTS extends MQTemplateS,
        MRT extends MQRoutingTemplate<MTS, MP, E, P, C>> implements SmartInitializingSingleton, Ordered {
    private ApplicationContext applicationContext;

    private GenericApplicationContext genericApplicationContext;

    private Environment environment;

    @Override
    public int getOrder() {
        return Integer.MIN_VALUE;
    }

    public AbstractMQConfiguration(ApplicationContext applicationContext, Environment environment) {
        this.applicationContext = applicationContext;
        this.genericApplicationContext = (GenericApplicationContext) applicationContext;
        this.environment = environment;
        SpringUtil.setApplicationContextJack(applicationContext);
        EnvironmentUtil.setEnvironmentJack(environment);
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public GenericApplicationContext getGenericApplicationContext() {
        return genericApplicationContext;
    }

    public Environment getEnvironment() {
        return environment;
    }

    public abstract MP mqProperties();

    public abstract MRT mqRoutingTemplate();


}
